<?xml version="1.0" encoding="iso-8859-1"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>FusionCharts v3 Documentation</title>
<link rel="stylesheet" href="Style.css" type="text/css" />
</head>

<body>
<table width="98%" border="0" cellspacing="0" cellpadding="3" align="center">
  <tr> 
    <td><h2 class="pageHeader">Using FusionCharts with ASP.NET (VB.NET)&gt; Charting Data from Forms </h2></td>
  </tr>
  <tr> 
    <td valign="top" class="text"><p>In this section, we'll show you how to use FusionCharts with ASP.NET to plot data collected in forms. </p>
      <p>We'll build a simple restaurant sales example, where the user will enter the items sold by a restaurant in a given week. This data will be submitted in a form to the server. We'll acquire this data and plot in on a chart. For the sake of simplicity, we wouldn't do any processing on this data. However, your real life applications might process data before presenting it on the chart. </p>
    <p><strong>Before you go further with this page, we recommend you to please see the previous section &quot;Basic Examples&quot; as we start off from concepts explained in that page. </strong></p></td>
  </tr>
  <tr>
    <td valign="top" class="highlightBlock">The code examples contained in this page are present in<span class="codeInline"> Download Package &gt; Code &gt; VB_NET </span> &gt; <span class="codeInline">FormBased</span> folder. </td>
  </tr>
  <tr>
    <td valign="top" class="text">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" class="header">Building the Form </td>
  </tr>
  <tr>
    <td valign="top" class="text">The form is contained in <span class="codeInline">Default.aspx</span> and looks as under: </td>
  </tr>
  <tr>
    <td valign="top" class="text"><img src="Images/Code_Form.gif" width="445" height="387" class="imageBorder" /></td>
  </tr>
  <tr>
    <td valign="top" class="text">It's a very simple form which submits to itself. As such, we wouldn't go into the code of this form. You can directly open the source from download and see it. </td>
  </tr>
  <tr>
    <td valign="top" class="text">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" class="header">Requesting the data and Creating the Chart </td>
  </tr>
  <tr>
    <td valign="top" class="text">The work of requesting the data from submitted form and creating the chart is done in the code behind page <span class="codeInline">Default.aspx.vb</span>. </td>
  </tr>
  <tr>
    <td valign="top" class="codeBlock"><p class="codeBlock"><strong>					Private Sub ButtonChart_Click(ByVal sender As Object, ByVal e As System.EventArgs)</strong><br>
            &nbsp;<span class="codeComment">'We first request the data from the form (Default.aspx)</span><br>
            &nbsp;Dim desserts As Integer<br>
            &nbsp;Dim soups As Integer<br>
            &nbsp;Dim salads As Integer<br>
            &nbsp;Dim sandwiches As Integer<br>
            &nbsp;Dim beverages As Integer<br>
            &nbsp;soups = Integer.Parse(TextBoxSoups.Text)<br>
            &nbsp;salads = Integer.Parse(TextboxSalads.Text)<br>
            &nbsp;sandwiches = Integer.Parse(TextboxSandwiches.Text)<br>
            &nbsp;beverages = Integer.Parse(TextboxBeverages.Text)<br>
            &nbsp;desserts = Integer.Parse(TextboxDesserts.Text)<br>
            &nbsp;<span class="codeComment">'In this example, we're directly showing this data back on chart.<br>
&nbsp;'In your apps, you can do the required processing and then show the <br>
&nbsp;'relevant data only.<br>
&nbsp;'Now that we've the data in variables, we need to convert this into XML.<br>
&nbsp;'The simplest method to convert data into XML is using string concatenation.</span><br>    
            &nbsp;Dim xmlData As String = String.Empty<br>
            <span class="codeComment">&nbsp;'Initialize &lt;chart&gt; element</span><br>
            &nbsp;xmlData = "&lt;chart caption='Sales by Product Category' subCaption='For this week' showPercentValues='1' pieSliceD" &amp;_<br>
            &nbsp;"epth='30' showBorder='1'&gt;"<br>
            <span class="codeComment">&nbsp;'Add all data</span><br>
            &nbsp;xmlData = (xmlData &amp;("&lt;set label='Soups' value='" _<br>
                        &nbsp;&nbsp;&amp;(soups &amp;"' /&gt;")))<br>
            &nbsp;xmlData = (xmlData &amp;("&lt;set label='Salads' value='" _<br>
                        &nbsp;&nbsp;&amp;(salads &amp;"' /&gt;")))<br>
            &nbsp;xmlData = (xmlData &amp;("&lt;set label='Sandwiches' value='" _<br>
                        &nbsp;&nbsp;&amp;(sandwiches &amp;"' /&gt;")))<br>
            &nbsp;xmlData = (xmlData &amp;("&lt;set label='Beverages' value='" _<br>
                        &nbsp;&nbsp;&amp;(beverages &amp;"' /&gt;")))<br>
            &nbsp;xmlData = (xmlData &amp;("&lt;set label='Desserts' value='" _<br>
                        &nbsp;&nbsp;&amp;(desserts &amp;"' /&gt;")))<br>
            &nbsp;'Close &lt;chart&gt; element<br>
            &nbsp;xmlData = (xmlData &amp;"&lt;/chart&gt;")<br>
            <span class="codeComment">&nbsp;'Create the chart - Pie 3D Chart with data from xmlData</span><br>
           &nbsp; LiteralChart.Text = InfoSoftGlobal.FusionCharts.RenderChart("../../FusionCharts/Pie3D.swf", "", xmlData, "Sales", "500", "300", False, False)<br>
        End Sub<br>
    
    </p></td>
  </tr>
  <tr>
    <td valign="top" class="text"><p>As you can see in the above code, we're doing the following:</p>
      <ul>
        <li>Requesting data from the submitted form and storing it in local variables when the button 'Chart it' is pressed.</li>
        <li>Creating an XML data document using string concatenation and storing it in <span class="codeInline">xmlData</span> variable  </li>
        <li>Creating a Pie 3D chart using <span class="codeInline">Functions.RenderChart()</span> function and passing <span class="codeInline">xmlData</span> as <span class="codeInline">dataXML</span> for the chart. </li>
      </ul>
    <p>When you finally run the code, you'll see a chart as under: </p></td>
  </tr>
  <tr>
    <td valign="top" class="text"><img src="Images/Code_FormChart.jpg" width="468" height="268" class="imageBorder" /></td>
  </tr>
</table>
</body>
</html>
